package uw10.app.display;

import uw10.app.data.Event;
import android.R.integer;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.Typeface;

public class EventIconRenderer
{
	private Canvas c;
	private EventIconFactory eif;
	private RatingColorFactory rcf;
	
	public EventIconRenderer(EventIconFactory eif, RatingColorFactory rcf)
	{
		c = new Canvas();
		this.eif = eif;
		this.rcf = rcf;
	}
	
	public void render(Bitmap bitmap, Event event)
	{
		c.setBitmap(bitmap);
		
		Paint p = new Paint();
		p.setStyle(Paint.Style.FILL);
		
		p.setColor(0xffffffff);
		c.drawRect(c.getClipBounds(), p);
		
		Rect r = new Rect();
		c.getClipBounds(r);
		int w = r.width();
		int h = r.height();
		r.left += w * 0.03;
		r.right -= w * 0.03;
		r.top += h * 0.03;
		r.bottom -= h * 0.03;
		

		r.offset(1, 2);
		p.setColor(0xffdddddd);
		c.drawRect(r, p);
		r.offset(-1, -2);
		
		p.setColor(rcf.getColor(event.rating));
		c.drawRect(r, p);
		
		r.bottom -= 10;
		
		c.drawBitmap(eif.getIcon(event), null, r, null);
		
		p.setColor(Color.BLACK);
		p.setTypeface(Typeface.SANS_SERIF);
		p.setTextSize(10);
		p.setTextScaleX(2);
		p.setTextAlign(Align.CENTER);
		
		String text = event.hours + ":" + event.minutes;
		if (event.hours < 10) text = "0" + text;
		if (event.minutes < 10) text = text + "0";
		
		c.drawText(text, c.getWidth() / 2, c.getHeight() - 6, p);
	}
}
